﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.SessionState;

namespace Cherry.Agile.RpcService
{
    /// <summary>
    /// 通信服务Http请求处理入口
    /// </summary>
    public class RpcServiceHandler : IHttpHandler, IRequiresSessionState
    {
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                byte[] request = new byte[context.Request.InputStream.Length];
                context.Request.InputStream.Read(request, 0, request.Length);

                byte[] response = ServiceDispatcher.Process(request);
                context.Response.BinaryWrite(response);
            }
            catch (Exception ex)
            {
                context.Response.BinaryWrite(new byte[] { 0xFF });
                ServiceDispatcher.FatalMsg = string.Format("@{0},Fr[{1}],{2},{3}", DateTime.Now, context.Request.UserHostAddress, ex.Message, ex.StackTrace);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
